<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('扫码枪分配')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-post-add">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="name" id="name" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">工号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="workNumber" id="workNumber" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">扫码枪device id：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="deviceId" id="deviceId" required>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		$("#form-post-add").validate({
			onkeyup: false,
			rules:{
				workNumber:{
					remote: {
		                url: "/api/distribution/checkExists",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"workNumber" : function() {
		                        return $.common.trim($("#workNumber").val());
		                    }
		                }
		            }
				},
				deviceId:{
					remote: {
		                url: "/api/distribution/checkExists",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"deviceId" : function() {
		                        return $.common.trim($("#deviceId").val());
		                    }
		                }
		            }
				}
			},
			messages: {
		        "workNumber": {
		            remote: "工号已经存在"
		        },
		        "deviceId": {
		            remote: "扫描枪已经存在"
		        }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save("/api/distribution/add", $('#form-post-add').serialize());
	        }
	    }
	</script>
</body>
</html>
